import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:ost_flutter_module/class/entity/store/store_address_entity.dart';
import 'package:ost_flutter_module/class/store/address_page/bloc/address_page_bloc.dart';
import 'package:ost_flutter_module/class/store/address_page/store_address_edit_page_body.dart';
import 'package:ost_flutter_module/common/styles.dart';
import 'package:ost_flutter_module/common/utils.dart';
import 'package:ost_flutter_module/widget/custom_widget/custome_scaffold.dart';
import 'package:ost_flutter_module/widget/custom_widget/text_button.dart';

class StoreAddressEditPage extends StatelessWidget {
  final EditAddress type;
  final StoreAddressEntity entity;

  const StoreAddressEditPage({Key key, this.type, this.entity})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      create: (context) => AddressPageBloc(),
      child: GScaffold(
        title: Text(type == EditAddress.add ? '新增地址' : '编辑地址',
            style: TextStyles.appBarTitleStyle),
        actions: [
          type == EditAddress.edit
              ? GTextButton(
                  title: '删除',
                  onPressed: () async {
                    var tag = await showOkCancelAlertDialog(
                        context: context,
                        message: '确定删除改地址吗？',
                        cancelLabel: '取消',
                        okLabel: '确定');
                    if (tag == OkCancelResult.ok) Navigator.pop(context);
                  },
                )
              : Container()
        ],
        body: StoreAddressEditPageBody(type: type, entity: entity),
      ),
    );
  }
}
